package de.fhin.mas.agents.gripper.behaviours;

import jade.core.Agent;
import jade.core.behaviours.OneShotBehaviour;
import jade.lang.acl.ACLMessage;
import de.fhin.mas.MASEvents;
import de.fhin.mas.agents.gripper.GripperAgent;

public class MoveGrapplerToStandbyPosition extends OneShotBehaviour {

	private static final long serialVersionUID = 2228321923634333963L;

	private final GripperAgent gripperAgent;

	public MoveGrapplerToStandbyPosition(Agent superAgent) {
		super(superAgent);
		gripperAgent = (GripperAgent) superAgent;
	}

	/**
	 * Bewegt den unbeladenen Greifarm in Standbyposition
	 */
	public void moveGrappler() {
		// Versucht den Greifarm in Standbyposition zu bringen. Liefert zufällig den Rückgabewert true oder false
		// gripperAgent.getRandomBoolean()
		if (true) {
			gripperAgent.printLn("Object unloaded. Grappler in standby-position");

			ACLMessage objectUnloadedMsg = new ACLMessage(ACLMessage.INFORM);
			objectUnloadedMsg.setConversationId(MASEvents.OBJECT_UNLOADED.getName());
			((GripperAgent) myAgent).sendToAll(objectUnloadedMsg);

			gripperAgent.setGrapplerStatus("STANDBY");
		} else {
			gripperAgent.printLn("Error: Unable to move Grappler to standby-position!");
		}
	}

	@Override
	public void action() {
		moveGrappler();
	}

	@Override
	public int onEnd() {
		return 0;
	}

}
